<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use App\Seller_info;

class MuserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    
    //利用中间件检测用户的登录状态.
    protected $middleware = ['App\Http\Middleware\Authenticate'=>[] ];

    //卖家审核
    public function musercheck($sid)
    {   
       
        $mobile = Seller_info::where('sid',$sid)->first();
        $mobile->s_status = 1;
        $mobile->save();
        if($_POST){
          $musercheck = [
            's_name' => $_POST['s_name'],
            's_mobile' => $_POST['s_mobile'],
            's_jobcity' => $_POST['s_jobcity'],
            's_age' =>$_POST['s_age'],
            's_address' =>$_POST['s_address'],
            'pubtime' => time(),
            'car_price' => $_POST['car_price'],
            'car_cyh' => $_POST['car_cyh'],
            's_status' => $_POST['s_status']
        ];
            return DB::table('seller_checks')->insert($musercheck)?redirect("addcar/$_POST[car_cyh]"):redirect('musercheck');

        }else{

            return view('admin.musercheck',['mobile'=>$mobile]);
      } 


    }

    //卖家信息列表
    public function muserchecklist()
    {
        $ml = DB::table('seller_checks')->simplePaginate(6);
        //print_r($ml);exit;
        return view('admin.muserchecklist',['ml'=>$ml]);
    }

    //卖家信息修改
    public function musercheckupdate($id){
        if(!empty($_POST)){
            $row = [];
            $row['s_name'] = $_POST['s_name'];
            $row['s_mobile'] = $_POST['s_mobile'];
            $row['s_jobcity'] = $_POST['s_jobcity'];
            $row['s_age'] = $_POST['s_age'];
            $row['s_address'] = $_POST['s_address'];
            $row['s_status'] = $_POST['s_status'];
            $row['pubtime'] = time();
            $row['car_price'] = $_POST['car_price'];
            $row['car_cyh'] = $_POST['car_cyh'];
            return DB::table('seller_checks')->where('s_id',$id)->update($row)?redirect('muserchecklist'):redirect('musercheckupdate');
        }
        $mcu = DB::table('seller_checks')->where('s_id',$id)->first();
        
        return view('admin.musercheckupdate',['mcu'=>$mcu]);
    }
    //卖家信息删除
    public function musercheckdelete($id){
        //dd($id);
        return DB::table('seller_checks')->where('s_id',$id)->delete()?redirect('muserchecklist'):'false';
        
    }

}
